package org.example.code.test2024.nine_mouth;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class test0920 {

    public static void main(String[] args) {
        B b = new B("jack", 10);
        A a = (A) b;
        System.out.println(a.getName());
        a.setName("vivian");
        System.out.println(b.getName());
    }

    public int[] getSneakyNumbers(int[] nums) {
        Map<Integer,Integer> map = new HashMap<>();
        for(int i=0;i<nums.length;i++){
            if(map.containsKey(nums[i])){
                map.put(nums[i],map.get(nums[i])+1);
            }else{
                map.put(nums[i],1);
            }
        }
        int[] res = new int[2];
        int k=0;
        for (Map.Entry<Integer,Integer> entry : map.entrySet()) {
            if(k==2){
                break;
            }
            if(entry.getValue()==2){
                res[k] = entry.getKey();
                k++;
            }
        }
        return res;
    }

    public long maxScore(int[] a, int[] b) {
        int m = a.length;
        long[] dp = new long[m+1];
        Arrays.fill(dp,Long.MIN_VALUE/2);
        dp[0]=0;
        for(int t:b){
            for(int i=m;i>0;i--){
                dp[i]=Math.max(dp[i],dp[i-1]+(long)t*a[i-1]);
            }
        }
        return dp[m];
    }

    public int minValidStrings(String[] words, String target) {
        int n=target.length();
        int[] dp = new int[n+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int i = 1; i <= n; i++) {
            for (String word : words) {
                int wordLen = word.length();
                if (i >= wordLen && target.substring(i - wordLen, i).equals(word)&&dp[i-wordLen]!=Integer.MAX_VALUE) {
                    dp[i] = Math.min(dp[i], dp[i - wordLen] + 1);
                }
            }
        }
        return dp[n] == Integer.MAX_VALUE ? -1 : dp[n];
    }




}
